package NetWork;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;

public class UdpDictServer extends UdpEchoServer{  //能复用的直接继承,不能复用的就重写来进行扩展

    private HashMap<String,String> dict = null;
    public UdpDictServer(int port) throws SocketException {
        super(port);

        dict = new HashMap<>();
        dict.put("hello","你好");
        dict.put("sheep","绵羊");
        dict.put("pig","猪");
        //可以放无限多的元素
    }


    //重写process方法,实现输入中文回复英文
    @Override
    public String process(String request){
        return dict.getOrDefault(request,"该词汇没有查询到.");
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer sever = new UdpDictServer(9090);
        sever.start();
    }
}
